package com.dongjiantong.common.utils;/**
 * Created by cao on 2017/11/15.
 */

/**
 * 整形处理
 * @author cao
 * @create 2017-11-15 下午3:27
 **/
public final class IntegerUtil {

    public static boolean isNull(Object object)
    {
        if(object==null)
        {
            return true;
        }
        return  false;
    }

    public  static  Integer toInt(String str)
    {
        if(isNull(str))
        {
            return 0;
        }
        if(str=="")
        {
            return 0;
        }

        try {
            return Integer.parseInt(str);
        }catch (Exception ex)
        {
            return 0;
        }

    }

    public static  Long toLong(String str)
    {
        if(isNull(str))
        {
            return 0L;
        }
        if(str=="")
        {
            return 0L;
        }
        try {
            return Long.parseLong(str);
        }catch (Exception ex)
        {
            return 0L;
        }
    }
    public static  Long toLong(Object obj)
    {

        try {
            return Long.valueOf(String.valueOf(obj));
        }catch (Exception ex)
        {
            return 0L;
        }
    }

    public static Integer toInt(Integer str,int defaultVal)
    {
        if(str==null) {
            return defaultVal;
        }

        return str;
    }

    public static Integer toInt(Integer str)
    {
        if(str==null) {
            return 0;
        }

        return str;
    }
}
